<?php

/**
* ownCloud - ajax frontend
*
* @author Robin Appelman
* @copyright 2010 Robin Appelman icewind1991@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/

// Check if we are a user
OCP\User::checkLoggedIn();

$dir = JRequest::getInt('dir', 0); 

if(!$dir) {
   header("HTTP/1.0 404 Not Found");
   $tmpl = new OC_Template('', '404', 'base');
   $tmpl->assign('error', '文件不存在！');
   $tmpl->printPage();
   return; 
}

if(!DelayTaskJob::checkOwner($dir, OC_User::getUser())) {
   header("HTTP/1.0 404 Not Found");
   $tmpl = new OC_Template('', '404', 'base');
   $tmpl->assign('error', '文件不存在');
   $tmpl->printPage();
   return; 
}

$user = PFactory::getMasterUser();
$companyid = $user->id; 

$datadir = getUserDataDir($companyid);
$extdir = getUserExtDir($companyid);
if(!is_dir(OC::$SERVERROOT."/data".$datadir."/company/" . $extdir . "/resumes/download/" . $dir. "/download")) {
   header("HTTP/1.0 404 Not Found");
   $tmpl = new OC_Template('', '404', 'base');
   $tmpl->assign('error', '文件不存在');
   $tmpl->printPage();
   return; 
}


\OC\Files\Filesystem::tearDown();
\OC\Files\Filesystem::initMountPoints($companyid);

$storage = \OC\Files\Filesystem::getView();
$storage->chroot($companyid . "/resumes/download/");
OC_Files::get($dir, array("download"), $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
